package com.gaolang.controller;

import com.gaolang.dao.UserMapper;
import com.gaolang.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author DELLHL
 */
@Controller
public class AjaxController {

    @Autowired
    UserMapper userMapper;

/*    @RequestMapping("/register")
    @ResponseBody
    public String register(String name){
        String flag = "";
        List<User> userList = userMapper.selectList(null);
        for (int i = 0; i < userList.size(); i++) {
            if (userList.get(i).getUsername().equals(name)){
                flag = "用户名已存在";
                return flag;
            }
        }
        return flag;
    }*/

    @RequestMapping("/register")
    @ResponseBody
    public String register(String name){
        String flag = "";
        List<User> userList = userMapper.selectList(null);
        for (int i = 0; i < userList.size(); i++) {
            System.out.println(userList.get(i).getUsername());
            if (userList.get(i).getUsername().equals(name)){
                return "用户名已存在";
            }
        }
/*        if (name.equals("gaolang")){
            flag = "OK";
        }else {
            flag = "用户名已存在";
        }*/

        return flag;
    }

    @RequestMapping("/test")
    public String test(){
        return "test";
    }

}

